<template>
  <div>
    <el-row gutter="20">
      <el-col span="12">
        <el-card>
          <img src="../assets/imgs/img.png" alt="图片丢失啦" width="100%">
        </el-card>
      </el-col>
      <el-col span="12">
        <p style="font-size: 25px;font-weight: bold"></p>
        <el-divider></el-divider>
        <p style="color: #666;font-size: 20px;font-weight: bold">
          <span>车位编号：{{ space.locationNumber }}</span>
        </p>
        <p style="font-size: 20px;font-weight: bold">
          车辆位置信息：{{ space.location }}
        </p>

        <el-row gutter="20">
          <el-col span="8" style="text-align: center;margin-bottom: 30px">
            <el-card>
              <img src="../assets/imgs/ewm.jpg" alt="">
            </el-card>
            <p>扫码关注公众号</p>
          </el-col>
          <el-col span="8" style="text-align: center">
            <el-card>
              <img src="../assets/imgs/ewm.jpg" alt="">
            </el-card>
            <p>扫码下载app</p>
          </el-col>
          <el-col span="8" style="text-align: center">
            <el-card>
              <img src="../assets/imgs/ewm.jpg" alt="">
            </el-card>
            <p>扫码查看详情</p>
          </el-col>
        </el-row>
      </el-col>

      <el-button style="background-color: #0096dc" @click="open()">立即停车</el-button>
      <el-button style="background-color: #0096dc" @click="addMonthUser()">立即月租</el-button>
      <el-button style="background-color: #0096dc" @click="comment()">车位评论</el-button>
    </el-row>

    <el-dialog title="预约车位" :visible.sync="dialogFormVisible">
      <el-form :model="stop" :rules="rules" ref="stop" label-width="100px" class="demo-ruleForm">
        <el-form-item label="车牌号" aria-placeholder="请输入车牌号" prop="carId">
          <el-input v-model="stop.carId"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="stopCar()" style="position: relative;right: 45px">立即预约车位</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 评论   -->
    <el-dialog title="车位评论" :visible.sync="dialogFormVisibleComment">
      <div class="comments">
        <div class="comment-wrap">
          <div class="photo">
            <div class="avatar"></div>
          </div>
          <div class="comment-block">
            <el-form>
              <el-form-item>
                <el-input type="textarea" v-model="locationComment.comment" placeholder="说点儿什么...."></el-input>
              </el-form-item>
            </el-form>
            <el-button @click="addComment()">发送</el-button>
          </div>
        </div>

        <div class="comment-wrap" v-for="comment in commentDate">

          <div class="comment-block">
            <p class="comment-text">{{comment.nickname}}:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp{{ comment.comment }}</p>
            <div class="bottom-comment">
              <div class="comment-date">{{ comment.createTime }}</div>
              <ul class="comment-actions">
                <li class="complain">Complain</li>
                <li class="reply">Reply</li>
              </ul>
            </div>
          </div>
        </div>

      </div>
    </el-dialog>
  </div>

</template>
<style>

body {
  background-color: #f0f2fa;
  font-family: "PT Sans", "Helvetica Neue", "Helvetica", "Roboto", "Arial", sans-serif;
  color: #555f77;
  -webkit-font-smoothing: antialiased;
}


p {
  line-height: 1.3125rem;
}

.comments {
  margin: 2.5rem auto 0;
  max-width: 60.75rem;
  padding: 0 1.25rem;
}

.comment-wrap {
  margin-bottom: 1.25rem;
  display: table;
  width: 100%;
  min-height: 5.3125rem;
}

.photo {
  padding-top: 0.625rem;
  display: table-cell;
  width: 3.5rem;
}

.photo .avatar {
  height: 2.25rem;
  width: 2.25rem;
  border-radius: 50%;
  background-size: contain;
}

.comment-block {
  padding: 1rem;
  background-color: #fff;
  display: table-cell;
  vertical-align: top;
  border-radius: 0.1875rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.08);
}

.comment-block textarea {
  width: 100%;
  max-width: 100%;
}

.comment-text {
  margin-bottom: 1.25rem;
  text-align: left;
}

.bottom-comment {
  color: #acb4c2;
  font-size: 0.875rem;
}

.comment-date {
  float: left;
}

.comment-actions {
  float: right;
}

.comment-actions li {
  display: inline;
}

.comment-actions li.complain {
  padding-right: 0.625rem;
  border-right: 1px solid #e1e5eb;
}

.comment-actions li.reply {
  padding-left: 0.625rem;
}
</style>
<script>
export default {
  data() {
    return {
      commentDate: [],
      space: '',
      dialogFormVisibleComment: false,
      dialogFormVisible: false,
      user: {
        locationNumber: '',
        id: '',
        realName: '',
        carId: '',
      },
      stop: {
        locationNumber: '',
        carId: '',
      },
      locationComment: {
        nickname: '',
        comment: '',
        locationNumber: ''
      },
      rules: {
        carId: [
          {required: true, message: '请输入车牌号', trigger: 'blur'},
          {min: 7, max: 7, message: '长度为八位的车牌', trigger: 'blur'}
        ],
      },
    };

  },

  methods: {
    addComment() {
      this.locationComment.locationNumber = localStorage.getItem('locationNumber');
      this.locationComment.nickname = localStorage.getItem('nickname');
      console.log(this.locationComment)
      let url = 'http://localhost:8080/comment/newComment'
      this.axios.post(url, this.locationComment).then((response) => {
        let responseBody = response.data
        if (responseBody.code = 200) {
          this.$message({
            showClose: true,
            message: '发送成功',
            type: 'success'
          });
          this.locationComment.comment=''
          this.loadCommentList()
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'success'
          });
        }
      });
    },
    comment() {
      this.dialogFormVisibleComment = true
      this.loadCommentList()
    },
    loadCommentList() {

      let url = 'http://localhost:8080/comment/getCommentList?locationNumber='+localStorage.getItem('locationNumber')
      console.log(url)
      this.axios.get(url).then((response) => {
        let responseBody = response.data
        if (responseBody.code == 200) {
          this.commentDate = responseBody.data
          console.log(this.commentDate)
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });
    },
    open() {
      this.dialogFormVisible = true
    },
    stopCar() {
      this.stop.locationNumber = localStorage.getItem('locationNumber')
      let url = 'http://localhost:8080/car/carIn'
      console.log(this.stop)
      this.axios.post(url, this.stop).then((response) => {
        let responseBody = response.data
        if (responseBody.code == 200) {
          this.$message({
            showClose: true,
            message: '预约成功',
            type: 'success'
          });
          this.stop.carId = '';
          this.dialogFormVisible=false
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });
    },
    addMonthUser() {
      let url = 'http://localhost:8080/mouthUser/addMouthUser'
      this.user.locationNumber = localStorage.getItem('locationNumber')
      this.user.realName = localStorage.getItem('realName')
      this.user.cardId = localStorage.getItem('cardId')
      console.log(this.user)
      this.axios.post(url, this.user).then((response) => {
        let responseBody = response.data
        if (responseBody.code == 200) {
          window.location.href = "http://localhost:8080/pay/openMonth"
          this.$message({
            showClose: true,
            message: '添加成功',
            type: 'success'
          });
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });
    },
    loadInfo() {
      let url = 'http://localhost:8080/ParkingSpace/getParkingSpace?locationNumber=' + localStorage.getItem('locationNumber')
      console.log(url)
      this.axios.post(url).then((response) => {
        let responseBody = response.data
        if (responseBody.code == 200) {
          this.space = responseBody.data
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });

    }
  },
  created() {
    this.loadInfo();
  }
}

</script>

